import request from '@/utils/request'
import type { UserResponseData, User, AllRoleResponseData, SetRoleData } from './type'
enum API {
    // 获取全部用户账号信息
    ALLUSER_URL = "/admin/acl/user/",
    // 新增用户
    ADDUSER_URL = "/admin/acl/user/save",
    // 更新用户
    UPDATEUSER_URL = "/admin/acl/user/update",
    // 根据用户获取角色数据
    ALLROLE_URL = "/admin/acl/user/toAssign/",
    // 给用户分配角色的接口
    SETROLE_URL = "/admin/acl/user/doAssignRole",
    // 删除某一个账号
    DELETEUSER_URL = "/admin/acl/user/remove/",
    // 批量删除账号
    DELETEUSERALL_URL = "/admin/acl/user/batchRemove",
}

// 获取全部用户账号信息
export const reqUserInfo = (pageNo: number, limit: number, keyword: string) => request.get<any, UserResponseData>(API.ALLUSER_URL + `${pageNo}/${limit}/?username=${keyword}`)
// 新增或更新用户
export const reqAddOrUpdateUser = (data: User) => {
    if (data.id) {
        return request.put<any, any>(API.UPDATEUSER_URL, data)
    } else {
        return request.post<any, any>(API.ADDUSER_URL, data)
    }
}
// 根据用户获取角色数据
export const reqAllRole = (userId: number) => request.get<any, AllRoleResponseData>(API.ALLROLE_URL + userId)
// 给用户分配角色
export const reqSetUserRole = (data: SetRoleData) => request.post<any, any>(API.SETROLE_URL, data)
// 删除某一个账号
export const reqDelUser = (id: number) => request.delete<any, any>(API.DELETEUSER_URL + id)
// 批量删除账号
export const reqDelUserAll = (ids: number[]) => request.delete<any, any>(API.DELETEUSERALL_URL, { data: ids })